package com.xique.park.service.biz.service.impl;

import com.xique.common.core.domain.R;
import com.xique.common.core.utils.OrikaUtil;
import com.xique.park.api.request.RemoteReceiveCouponRequest;
import com.xique.park.bean.domain.ParkCouponPp;
import com.xique.park.bean.domain.ParkCouponPpOn;
import com.xique.park.constant.CouponConstant;
import com.xique.park.service.biz.service.ICouponBizService;
import com.xique.park.service.service.IParkCouponPpOnService;
import com.xique.park.service.service.IParkCouponPpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author shd
 * @create 2022/1/12 14:46
 */
@Service
public class CouponBizServiceImpl implements ICouponBizService {

    @Autowired
    private IParkCouponPpService parkCouponPpService;

    @Autowired
    private IParkCouponPpOnService parkCouponPpOnService;

    @Override
    public R<Boolean> receiveCoupon(RemoteReceiveCouponRequest request) {

        //历史记录表
        ParkCouponPp parkCouponPp = new ParkCouponPp();
        parkCouponPp.setParkId(request.getParkId());
        parkCouponPp.setParkingSerial(request.getParkingSerial());
        parkCouponPp.setPlate(request.getPlate());
        parkCouponPp.setGrantSerial(request.getGrantSerial());
        parkCouponPp.setType(Long.valueOf(request.getType()));
        parkCouponPp.setValue(Long.valueOf(request.getValue()));
        parkCouponPp.setReason(request.getReason());
        parkCouponPp.setStoreName(request.getStoreName());
        parkCouponPp.setStoreCode(request.getStoreCode());
        parkCouponPp.setCouponName(request.getCouponName());
        parkCouponPp.setCouponCode(request.getCouponCode());
        parkCouponPp.setExpireTime(request.getExpireTime());
        parkCouponPp.setCouponStatus(CouponConstant.COUPON_AVAILABLE);
        parkCouponPpService.insertParkCouponPp(parkCouponPp);
        //未使用表，使用或者失效以后要删除记录
        ParkCouponPpOn parkCouponPpOn = OrikaUtil.convert(parkCouponPp, ParkCouponPpOn.class);
        parkCouponPpOnService.insertParkCouponPpOn(parkCouponPpOn);

        return R.ok();
    }
}
